home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / ostack.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.3 KB  |  90 lines

  1. /* Copyright (C) 1991, 1994, 1996, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: ostack.h,v 1.2 2000/09/19 19:00:47 lpd Exp $ */
  20. /* Definitions for Ghostscript operand stack */
  21.  
  22. #ifndef ostack_INCLUDED
  23. #  define ostack_INCLUDED
  24.  
  25. #include "iostack.h"
  26. #include "icstate.h"        /* for access to op_stack */
  27.  
  28. /* Define the operand stack pointers for operators. */
  29. #define iop_stack (i_ctx_p->op_stack)
  30. #define o_stack (iop_stack.stack)
  31.  
  32. #define osbot (o_stack.bot)
  33. #define osp (o_stack.p)
  34. #define ostop (o_stack.top)
  35.  
  36. /* Macro to ensure enough room on the operand stack */
  37. #define check_ostack(n)\
  38.   if ( ostop - osp < (n) )\
  39.     { o_stack.requested = (n); return_error(e_stackoverflow); }
  40.  
  41. /* Operand stack manipulation. */
  42.  
  43. /* Note that push sets osp to (the new value of) op. */
  44. #define push(n)\
  45.   BEGIN\
  46.     if ( (op += (n)) > ostop )\
  47.       { o_stack.requested = (n); return_error(e_stackoverflow); }\
  48.     else osp = op;\
  49.   END
  50.  
  51. /*
  52.  * Note that the pop macro only decrements osp, not op.  For this reason,
  53.  *
  54.  *      >>>     pop should only be used just before returning,  <<<
  55.  *      >>>     or else op must be decremented explicitly.      <<<
  56.  */
  57. #define pop(n) (osp -= (n))
  58.  
  59. /*
  60.  * Note that the interpreter does not check for operand stack underflow
  61.  * before calling the operator procedure.  There are "guard" entries
  62.  * with invalid types and attributes just below the bottom of the
  63.  * operand stack: if the operator returns with a typecheck error,
  64.  * the interpreter checks for underflow at that time.
  65.  * Operators that don't typecheck their arguments must check for
  66.  * operand stack underflow explicitly; operators that take a variable
  67.  * number of arguments must also check for stack underflow in those cases
  68.  * where they expect more than their minimum number of arguments.
  69.  * (This is because the interpreter can only recognize that a typecheck
  70.  * is really a stackunderflow when the stack has fewer than the
  71.  * operator's declared minimum number of entries.)
  72.  */
  73. #define check_op(nargs)\
  74.   if ( op < osbot + ((nargs) - 1) ) return_error(e_stackunderflow)
  75. /*
  76.  * Similarly, in order to simplify some overflow checks, we allocate
  77.  * a few guard entries just above the top of the o-stack.
  78.  */
  79.  
  80. /*
  81.  * The operand stack is implemented as a linked list of blocks:
  82.  * operators that can push or pop an unbounded number of values, or that
  83.  * access the entire o-stack, must take this into account.  These are:
  84.  *      (int)copy  index  roll  clear  count  cleartomark
  85.  *      counttomark  aload  astore  packedarray
  86.  *      .get/.putdeviceparams .gethardwareparams
  87.  */
  88.  
  89. #endif /* ostack_INCLUDED */
  90.